package com.carcontrol.rotate.base;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;

import androidx.multidex.MultiDex;


/**
 * 自定义Application
 * 
 * @author wutao
 *
 */
public class BaseApplication extends Application {
	private static final String TAG = "BaseApplication";

	public  static Context context;
	private static BaseApplication app;

	private boolean debug = false;
	private boolean test = false;
	private boolean testLog = false;
	public static int width;
	public static int height;
	public static float density;

	public static int width0 = 1280;
	public static int height0 = 480;


	private PackageInfo packageInfo;

	public static BaseApplication getInstance() {
		return app;
	}

	public boolean isDebug() {
		return debug;
	}

	public void setDebug(boolean debug) {
		this.debug = debug;
	}

	public boolean isTest() {
		return test;
	}

	public void setTest(boolean test) {
		this.test = test;
	}

	public boolean isTestLog() {
		return testLog;
	}

	public void setTestLog(boolean testLog) {
		this.testLog = testLog;
	}

//	public BaseApplication2() {
//		app = this;
//	}

//	public static synchronized BaseApplication2 getInstance() {
//		if (app == null) {
//			app = new BaseApplication2();
//		}
//		return app;
//	}

	@Override
	protected void attachBaseContext(Context base) {
		super.attachBaseContext(base);
		MultiDex.install(this);
	}

	@Override
	public void onCreate() {
		super.onCreate();

		app = this;

		DisplayMetrics metrics = new DisplayMetrics();
		WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
		wm.getDefaultDisplay().getMetrics(metrics);
		density = metrics.density;
		width = metrics.widthPixels;
		height = metrics.heightPixels;

		Log.e("BaseApplication2===", density+"==="+width+"==="+height);

		try {
			String packageName = getPackageName();
			packageInfo = getPackageManager().getPackageInfo(packageName, 0);
		} catch (Exception e) {
			e.printStackTrace();
		}

//		DisplayMetrics metrics = new DisplayMetrics();
//		WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
//		wm.getDefaultDisplay().getMetrics(metrics);
//		density = metrics.density;
//		width = metrics.widthPixels;
//		height = metrics.heightPixels;


//		ToastUtils.init(this);
//		initBle();
	}

	// 注册App异常崩溃处理器
	private void registerUncaughtExceptionHandler() {
		Thread.setDefaultUncaughtExceptionHandler(AppException.getAppExceptionHandler());
	}

	@Override
	public void onLowMemory() {
		super.onLowMemory();
		System.gc();
	}

}
